<template>
  <div class="others">
    <a class="history-trade" href="javascript:;" @click="toRecord">
      <i class="iconfont icon-lishijilu"></i>&nbsp;我的历史交易记录
      <div class="forward">
        <i class="iconfont icon-xiangyou"></i>
      </div>
    </a>

    <a class="price-sub clearfix" href="javascript:;" data-toggle="modal" @click="subscribePriceModal">
      <div class="one">
        <i class="iconfont icon-shezhijiage"></i>
      </div>
      <div class="two">
        <div>设置订阅价格</div>
        <div>设置订阅我需扣除的君元宝数量</div>
      </div>
      <div class="three">
        <div>
          <img src="~assets/images/junyuanbao@3x.png">&nbsp;&nbsp;
          <span class="subscribe-price" id="subscribePrice">{{subscribePrice}}</span>
        </div>
        <div class="forward">
          <i class="iconfont icon-xiangyou"></i>
        </div>
      </div>
    </a>

    <div class="concern clearfix">
      <a href="javascript:;" class="create" @click="toMyGameBuild">
        <img src="~assets/images/chuangjian@3x.png" class="img-responsive">
        <div class="key">创建的比赛</div>
        <div class="value" id="gamesCreateNum">{{gamesCreateNum}}</div>
      </a>

      <a href="javascript:;" class="join" @click="toMyGameJoin">
        <img src="~assets/images/canjia@3x.png" class="img-responsive">
        <div class="key">参加的比赛</div>
        <div class="value" id="gamesJoinNum">{{gamesJoinNum}}</div>
      </a>

      <a href="javascript:;" class="sub" @click="toSubscriptions">
        <img src="~assets/images/dingyuede@3x.png" class="img-responsive">
        <div class="key">订阅的牛人</div>
        <div class="value" id="rockmansSubNum">{{rockmansSubNum}}</div>
      </a>

      <a href="javascript:;" class="copy" @click="toMyLearn">
        <img src="~assets/images/toushide@3x.png" class="img-responsive">
        <div class="key">偷师的组合</div>
        <div class="value" id="portfoliosCopyNum">{{portfoliosCopyNum}}</div>
      </a>
    </div>

    <div class="relive" @click="reliveModal">
      <img src="~assets/images/fuhuo@2x.png" class="img-responsive">
    </div>
  </div>
</template>

<script>
  import RemoteDAO from 'common/remoteDAO'
  import CommonUtil from 'common/common.util'
  import Constant from 'common/constant'
  import LocalDAO from 'common/localDAO'

  export default {
    data () {
      return {
        gamesCreateNum: '-',
        gamesJoinNum: '-',
        rockmansSubNum: '-',
        portfoliosCopyNum: '-',
        subscribePrice:''
      }
    },
    props: {
      userCode: {
        type: String
      }
    },
    created: function () {
      this.fetchData();
    },
    methods: {
      fetchData(){
        var self = this;

        self.subscribePrice = LocalDAO.getSubscribePrice()
        let params = {
          userCode: self.userCode,
          actionFlag: '2',
          pageSize: '1',
          pageNo: '1',
          totalFlag: '1',
          gameKind: '',
          gameID: ''
        }
        // 查询创建的比赛数量
        RemoteDAO.callUC12008303(params, function (response) {
          if (response.error == "0") {
            _.each(response.data.body, function (item, index) {
              self.gamesCreateNum = item.TOTAL_NUM;

              // 更新分享页数据
              var shareSelfDetails = LocalDAO.getShareSelfDetails();
              shareSelfDetails.others.gamesCreateNum = self.gamesCreateNum;
              LocalDAO.setShareSelfDetails(shareSelfDetails);
            });
          }
        });

        // 查询参加的比赛数量
        params.actionFlag = '1'
        RemoteDAO.callUC12008303(params, function (response) {
          if (response.error == "0") {
            _.each(response.data.body, function (item, index) {
              self.gamesJoinNum = item.TOTAL_NUM;

              // 更新分享页数据
              var shareSelfDetails = LocalDAO.getShareSelfDetails();
              shareSelfDetails.others.gamesJoinNum = self.gamesJoinNum;
              LocalDAO.setShareSelfDetails(shareSelfDetails);
            });
          }
        });

        // 查询我订阅的牛人
        var argsUC12008314 = {};
        argsUC12008314.USER_CODE = self.userCode;
        argsUC12008314.COMMUNITY_STATUS = "1";
        argsUC12008314.COMMUNITY_TYPE = "3";
        RemoteDAO.callUC12008314(argsUC12008314, function (response) {
          if (response.error == "0") {
            _.each(response.data.body, function (item, index) {
              if (response.data.body.length > 0) {
                self.rockmansSubNum = response.data.body[0].MY_SUBSCRIBE_COUNT;

                // 更新分享页数据
                var shareSelfDetails = LocalDAO.getShareSelfDetails();
                shareSelfDetails.others.rockmansSubNum = self.rockmansSubNum;
                LocalDAO.setShareSelfDetails(shareSelfDetails);
              }
            });
          }
        });

        // 查询我偷师的组合数量
        RemoteDAO.callJCl11156(self.userCode, "", "0", "1", function (response) {
          if (response.error == "0") {
            self.portfoliosCopyNum = response.data.body.total_num;

            // 更新分享页数据
            var shareSelfDetails = LocalDAO.getShareSelfDetails();
            shareSelfDetails.others.portfoliosCopyNum = self.portfoliosCopyNum;
            LocalDAO.setShareSelfDetails(shareSelfDetails);
          }
        });

        // 更新分享页数据
        var shareSelfDetails = LocalDAO.getShareSelfDetails();
        shareSelfDetails.others.subscribePrice = LocalDAO.getSubscribePrice();
        LocalDAO.setShareSelfDetails(shareSelfDetails);
      },
      /**
       * 查看交易记录
       */
      toRecord(){
        var self = this;
        var nickname = LocalDAO.getNickname();
        if (typeof(nickname) === "undefined" || nickname === "") {
          RemoteDAO.callNativeLogin(function (response) {
            window.location.reload(true);
          });
        } else {
            self.$router.push({path:'/records',query:{userCode: LocalDAO.getUserCode()}})
        }
      },
      /**
       * 点击一键复活按钮
       */
      reliveModal(){
        var object = {};
        object.usercode = LocalDAO.getUserCode();
        // object.k2 = "";
        TDAPP.onEvent("5001", "", object);
        TDAPP.send();
        this.$store.dispatch('setModal',{visible:true,modalId:Constant.modal.RELIVE_MODAL});
      },
      /**
       * 设置订阅价格
       */
      subscribePriceModal(){
        var self = this;
        self.$store.dispatch('setModal',{visible:true,modalId:'subscribePriceModal',callback:function(response){
          if(response.error == 0){
            self.subscribePrice = response.subscribePrice
          }
        }});
      },
      /**
       * 跳转我参加的比赛
       */
      toMyGameJoin(){
        this.$router.push({path:'/game/mygames',query:{tab:'play'}})
      },
      /**
       * 跳转我创建的比赛
       */
      toMyGameBuild(){
        this.$router.push({path:'/game/mygames',query:{tab:'build'}})
      },
      /**
       * 跳转我订阅的牛人
       */
      toSubscriptions(){
        this.$router.push('/subscriptions')
      },
      /**
       * 跳转我偷师的组合
       */
      toMyLearn(){
        this.$router.push('/mylearngroup')
      }
    }
  }
</script>

<style scoped>

</style>
